﻿using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using HslCommunication.ModBus;
using HslCommunication.Reflection;

namespace HslCommunication.Profinet.Inovance
{
	/// <summary>
	/// 汇川的网络通信协议，适用于H5U 系列，底层走的是MODBUS-TCP协议，地址说明参见标记<br />
	/// Huichuan's network communication protocol is suitable for H5U series. 
	/// The bottom layer is MODBUS-TCP protocol. For the address description, please refer to the mark
	/// </summary>
	/// <remarks>
	/// H5U 系列控制器支持 M/B/S/X/Y 等 bit 型变量（也称线圈） 的访问、 D/R 等 word 型变量的访问；<br />
	/// 其中 M/B/S/X/Y 等 bit 型变量的访问， 是以不同的地址偏移来区分的， D/R 等 word 型变量的访问， 也是以不同的地址偏移来区分的；<br />
	/// H5U 控制器内部 W 元件， 不支持通信访问。<br /><br />
	/// 我们来看看本组件支持的地址类型及范围，首先是位操作的地址
	/// <list type="table">
	///   <listheader>
	///     <term>地址名称</term>
	///     <term>地址代号</term>
	///     <term>地址范围</term>
	///     <term>地址进制</term>
	///     <term>备注</term>
	///   </listheader>
	///   <item>
	///     <term>中间寄电器</term>
	///     <term>M</term>
	///     <term>M0-M7999</term>
	///     <term>10</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term></term>
	///     <term>B</term>
	///     <term>B0-B32767</term>
	///     <term>10</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term></term>
	///     <term>S</term>
	///     <term>S0-S4095</term>
	///     <term>10</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>输入</term>
	///     <term>X</term>
	///     <term>X0-X1777 或者X0.0-X177.7</term>
	///     <term>8</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>输出</term>
	///     <term>Y</term>
	///     <term>Y0-Y1777 或者Y0.0-Y177.7</term>
	///     <term>8</term>
	///     <term></term>
	///   </item>
	/// </list>
	/// 然后是字操作的地址
	/// <list type="table">
	///   <listheader>
	///     <term>地址名称</term>
	///     <term>地址代号</term>
	///     <term>地址范围</term>
	///     <term>地址进制</term>
	///     <term>备注</term>
	///   </listheader>
	///   <item>
	///     <term>数据寄存器</term>
	///     <term>D</term>
	///     <term>D0-D7999</term>
	///     <term>10</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term></term>
	///     <term>R</term>
	///     <term>R0-R32767</term>
	///     <term>10</term>
	///     <term></term>
	///   </item>
	/// </list>
	/// </remarks>
	// Token: 0x02000098 RID: 152
	public class InovanceH5UTcp : ModbusTcpNet
	{
		/// <summary>
		/// 实例化一个安川H5U 系列的网络通讯协议<br />
		/// Instantiate a network communication protocol of Yaskawa H5U series
		/// </summary>
		// Token: 0x06000B73 RID: 2931 RVA: 0x0004272E File Offset: 0x0004092E
		public InovanceH5UTcp()
		{
		}

		/// <summary>
		/// 指定服务器地址，端口号，客户端自己的站号来实例化一个安川H5U 系列的网络通讯协议<br />
		/// Specify the server address, port number, and client's own station number to instantiate a Yaskawa H5U series network communication protocol
		/// </summary>
		/// <param name="ipAddress">服务器的Ip地址</param>
		/// <param name="port">服务器的端口号</param>
		/// <param name="station">客户端自身的站号</param>
		// Token: 0x06000B74 RID: 2932 RVA: 0x00042738 File Offset: 0x00040938
		public InovanceH5UTcp(string ipAddress, int port = 502, byte station = 1) : base(ipAddress, port, station)
		{
		}

		/// <summary>
		/// 按字读取汇川PLC的数据信息，可以输入D0,R0 类型地址<br />
		/// Read Huichuan PLC's data information by word, you can enter D0, R0 type address
		/// </summary>
		/// <param name="address">PLC的真实的地址信息，可以输入D0,R0 类型地址</param>
		/// <param name="length">读取的数据的长度，按照字为单位</param>
		/// <returns>包含是否成功的结果对象信息</returns>
		// Token: 0x06000B75 RID: 2933 RVA: 0x00043398 File Offset: 0x00041598
		[HslMqttApi("ReadByteArray", "")]
		public override OperateResult<byte[]> Read(string address, ushort length)
		{
			OperateResult<string> operateResult = InovanceHelper.PraseInovanceH5UAddress(address, 3);
			bool flag = !operateResult.IsSuccess;
			OperateResult<byte[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<byte[]>(operateResult);
			}
			else
			{
				result = base.Read(operateResult.Content, length);
			}
			return result;
		}

		/// <summary>
		/// 按字写入汇川PLC的数据信息，可以输入D0,R0 类型地址<br />
		/// Data information written into Huichuan PLC by word, can enter D0, R0 type
		/// </summary>
		/// <param name="address">PLC的真实的地址信息，可以输入D0,R0 类型地址</param>
		/// <param name="value">等待写入的原始数据，长度为2的倍数</param>
		/// <returns>是否写入成功的结果信息</returns>
		// Token: 0x06000B76 RID: 2934 RVA: 0x000433D8 File Offset: 0x000415D8
		[HslMqttApi("WriteByteArray", "")]
		public override OperateResult Write(string address, byte[] value)
		{
			OperateResult<string> operateResult = InovanceHelper.PraseInovanceH5UAddress(address, 16);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<byte[]>(operateResult);
			}
			else
			{
				result = base.Write(operateResult.Content, value);
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Inovance.InovanceH5UTcp.Read(System.String,System.UInt16)" />
		// Token: 0x06000B77 RID: 2935 RVA: 0x00043418 File Offset: 0x00041618
		[DebuggerStepThrough]
		public override Task<OperateResult<byte[]>> ReadAsync(string address, ushort length)
		{
			InovanceH5UTcp.<ReadAsync>d__4 <ReadAsync>d__ = new InovanceH5UTcp.<ReadAsync>d__4();
			<ReadAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<byte[]>>.Create();
			<ReadAsync>d__.<>4__this = this;
			<ReadAsync>d__.address = address;
			<ReadAsync>d__.length = length;
			<ReadAsync>d__.<>1__state = -1;
			<ReadAsync>d__.<>t__builder.Start<InovanceH5UTcp.<ReadAsync>d__4>(ref <ReadAsync>d__);
			return <ReadAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Inovance.InovanceH5UTcp.Write(System.String,System.Byte[])" />
		// Token: 0x06000B78 RID: 2936 RVA: 0x0004346C File Offset: 0x0004166C
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, byte[] value)
		{
			InovanceH5UTcp.<WriteAsync>d__5 <WriteAsync>d__ = new InovanceH5UTcp.<WriteAsync>d__5();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.value = value;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<InovanceH5UTcp.<WriteAsync>d__5>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <summary>
		/// 按位读取汇川PLC的数据信息，可以输入M0,B0,S0,X0,Y0<br />
		/// Read the data of Huichuan PLC bit by bit, you can enter M0, B0, S0, X0, Y0
		/// </summary>
		/// <param name="address">汇川PLC的真实的位地址信息，可以输入M0,B0,S0,X0,Y0</param>
		/// <param name="length">等待读取的长度，按照位为单位</param>
		/// <returns>包含是否成功的结果对象</returns>
		// Token: 0x06000B79 RID: 2937 RVA: 0x000434C0 File Offset: 0x000416C0
		[HslMqttApi("ReadBoolArray", "")]
		public override OperateResult<bool[]> ReadBool(string address, ushort length)
		{
			OperateResult<string> operateResult = InovanceHelper.PraseInovanceH5UAddress(address, 1);
			bool flag = !operateResult.IsSuccess;
			OperateResult<bool[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<bool[]>(operateResult);
			}
			else
			{
				result = base.ReadBool(operateResult.Content, length);
			}
			return result;
		}

		/// <summary>
		/// 按位写入汇川PLC的数据信息，可以输入M0,B0,S0,X0,Y0<br />
		/// Write the data information of Huichuan PLC bit by bit, you can enter M0, B0, S0, X0, Y0
		/// </summary>
		/// <param name="address">汇川PLC的真实的位地址信息，可以输入M0,B0,S0,X0,Y0</param>
		/// <param name="values">等待写入的原始数据</param>
		/// <returns>是否写入成功</returns>
		// Token: 0x06000B7A RID: 2938 RVA: 0x00043500 File Offset: 0x00041700
		[HslMqttApi("WriteBoolArray", "")]
		public override OperateResult Write(string address, bool[] values)
		{
			OperateResult<string> operateResult = InovanceHelper.PraseInovanceH5UAddress(address, 15);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<bool[]>(operateResult);
			}
			else
			{
				result = base.Write(operateResult.Content, values);
			}
			return result;
		}

		/// <summary>
		/// 写入汇川PLC一个bool数据，可以输入M0,B0,S0,X0,Y0<br />
		/// Write a bool data to Huichuan PLC, you can enter M0, B0, S0, X0, Y0
		/// </summary>
		/// <param name="address">汇川PLC的真实的位地址信息，可以输入M0,B0,S0,X0,Y0</param>
		/// <param name="value">bool数据值</param>
		/// <returns>是否写入成功</returns>
		// Token: 0x06000B7B RID: 2939 RVA: 0x00043540 File Offset: 0x00041740
		[HslMqttApi("WriteBool", "")]
		public override OperateResult Write(string address, bool value)
		{
			OperateResult<string> operateResult = InovanceHelper.PraseInovanceH5UAddress(address, 5);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<bool[]>(operateResult);
			}
			else
			{
				result = base.Write(operateResult.Content, value);
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Inovance.InovanceH5UTcp.ReadBool(System.String,System.UInt16)" />
		// Token: 0x06000B7C RID: 2940 RVA: 0x00043580 File Offset: 0x00041780
		[DebuggerStepThrough]
		public override Task<OperateResult<bool[]>> ReadBoolAsync(string address, ushort length)
		{
			InovanceH5UTcp.<ReadBoolAsync>d__9 <ReadBoolAsync>d__ = new InovanceH5UTcp.<ReadBoolAsync>d__9();
			<ReadBoolAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<bool[]>>.Create();
			<ReadBoolAsync>d__.<>4__this = this;
			<ReadBoolAsync>d__.address = address;
			<ReadBoolAsync>d__.length = length;
			<ReadBoolAsync>d__.<>1__state = -1;
			<ReadBoolAsync>d__.<>t__builder.Start<InovanceH5UTcp.<ReadBoolAsync>d__9>(ref <ReadBoolAsync>d__);
			return <ReadBoolAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Inovance.InovanceH5UTcp.Write(System.String,System.Boolean[])" />
		// Token: 0x06000B7D RID: 2941 RVA: 0x000435D4 File Offset: 0x000417D4
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, bool[] values)
		{
			InovanceH5UTcp.<WriteAsync>d__10 <WriteAsync>d__ = new InovanceH5UTcp.<WriteAsync>d__10();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.values = values;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<InovanceH5UTcp.<WriteAsync>d__10>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Inovance.InovanceH5UTcp.Write(System.String,System.Boolean)" />
		// Token: 0x06000B7E RID: 2942 RVA: 0x00043628 File Offset: 0x00041828
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, bool value)
		{
			InovanceH5UTcp.<WriteAsync>d__11 <WriteAsync>d__ = new InovanceH5UTcp.<WriteAsync>d__11();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.value = value;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<InovanceH5UTcp.<WriteAsync>d__11>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <summary>
		/// 写入汇川PLC的一个字数据，可以输入D0,R0 类型地址<br />
		/// Write a word of data to Huichuan PLC, you can enter D0, R0 type address
		/// </summary>
		/// <param name="address">汇川PLC的真实地址，可以输入D0,R0 类型地址</param>
		/// <param name="value">short数据</param>
		/// <returns>是否写入成功</returns>
		// Token: 0x06000B7F RID: 2943 RVA: 0x0004367C File Offset: 0x0004187C
		[HslMqttApi("WriteInt16", "")]
		public override OperateResult Write(string address, short value)
		{
			OperateResult<string> operateResult = InovanceHelper.PraseInovanceH5UAddress(address, 6);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<bool[]>(operateResult);
			}
			else
			{
				result = base.Write(operateResult.Content, value);
			}
			return result;
		}

		/// <summary>
		/// 写入汇川PLC的一个字数据，可以输入D0,R0 类型地址&gt;br /&gt;
		/// Write a word of data to Huichuan PLC, you can enter D0, R0 type address
		/// </summary>
		/// <param name="address">汇川PLC的真实地址，可以输入D0,R0 类型地址</param>
		/// <param name="value">ushort数据</param>
		/// <returns>是否写入成功</returns>
		// Token: 0x06000B80 RID: 2944 RVA: 0x000436BC File Offset: 0x000418BC
		[HslMqttApi("WriteUInt16", "")]
		public override OperateResult Write(string address, ushort value)
		{
			OperateResult<string> operateResult = InovanceHelper.PraseInovanceH5UAddress(address, 6);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<bool[]>(operateResult);
			}
			else
			{
				result = base.Write(operateResult.Content, value);
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Inovance.InovanceH5UTcp.Write(System.String,System.Int16)" />
		// Token: 0x06000B81 RID: 2945 RVA: 0x000436FC File Offset: 0x000418FC
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, short value)
		{
			InovanceH5UTcp.<WriteAsync>d__14 <WriteAsync>d__ = new InovanceH5UTcp.<WriteAsync>d__14();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.value = value;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<InovanceH5UTcp.<WriteAsync>d__14>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Inovance.InovanceH5UTcp.Write(System.String,System.UInt16)" />
		// Token: 0x06000B82 RID: 2946 RVA: 0x00043750 File Offset: 0x00041950
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, ushort value)
		{
			InovanceH5UTcp.<WriteAsync>d__15 <WriteAsync>d__ = new InovanceH5UTcp.<WriteAsync>d__15();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.value = value;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<InovanceH5UTcp.<WriteAsync>d__15>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc />
		// Token: 0x06000B83 RID: 2947 RVA: 0x000437A2 File Offset: 0x000419A2
		public override string ToString()
		{
			return string.Format("InovanceH5UTcp[{0}:{1}]", this.IpAddress, this.Port);
		}
	}
}
